layui.use(['laypage', 'layer'], function () {
    var layer = layui.layer;
    /*=====分页 star =====*/
    var o_page = $('#o-page');
    if (o_page.length) {
        layui.laypage({
            cont: 'o-page'//对象ID
            , pages: parseInt(o_page.attr('data-pages')) //总页数
            , groups: 5 //连续显示分页数
            , skip: true
            , curr: function () { //通过url获取当前页，也可以同上（pages）方式获取
                var page = location.search.match(/page=(\d+)/);
                return page ? page[1] : 1;
            }()
            , jump: function (e, first) {
                //如果不是第一次加载，防止不停重复加载
                if (!first) {
                    if (location.search.match(/page=(\d+)/)) {//如果参数里面有page
                        //修改page的值
                        location.href = location.search.replace(/page=(\d+)/, 'page=' + e.curr);
                    } else if (location.search) {//如果有参数，参数没有page
                        //增加page参数
                        location.href = location.href + '&page=' + e.curr;
                    } else {//如果没有参数
                        //直接增加page参数
                        location.href = '?page=' + e.curr;
                    }
                }
            }
        });
    }
    /*=====分页 end =====*/
    /*=====删除 star =====*/
    $('.o-del-btn').on('click', function () {
        var _this = $(this);//当前点击对象
        layer.confirm('是否确认删除？', {
            icon: 3,
            shadeClose: true,
            closeBtn: 0,
            title: '提示'
        }, function (index) {
            var del_url = _this.attr('data-url');
            $.getJSON(del_url, function (rs) {
                if (rs.code === 0) {
                    layer.msg(rs.msg);
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);
                } else {
                    layer.msg(rs.msg);
                }
            });
            layer.close(index);
        });
    });
    /*=====删除 end =====*/
});